<template>
  <div class="chart-container">
    <el-row :gutter="10" type="flex" justify="center">
      <el-col :span="3"
              class="choose"><span>请选择标签:</span></el-col>
      <el-col :span="20"
              v-cloak>
        <el-select v-model="value"
                   clearable
                   @change="handleChange"
                   placeholder="请选择">
          <el-option v-for="item in options"
                     :key="item.value"
                     :label="item.label"
                     :value="item.value">
          </el-option>
        </el-select>
      </el-col>
    </el-row>

    <chart height="100%"
           width="100%"
           v-if="show"
           :id="value" />
  </div>
</template>

<script>
import Chart from '@/components/Charts/LineMarker'
import { getTagInfo } from '@/api/data'

export default {
  name: 'Battery',
  components: { Chart },
  data() {
    return {
      show: false,
      // tagId:'1',
      options: [],
      value: ''
    }
  },
  methods: {
    handleChange() {
      this.show = false
      this.$nextTick(() => {
        this.show = true
      })
    }
  },
  created() {
    getTagInfo().then(r => {
      r.tags.forEach((item, index) => {
        console.log(index)
        let obj = new Object()
        obj.value = item.id
        obj.label = item.id
        this.options.push(obj)
      })
    })
  }
}
</script>

<style scoped>
.main-content {
  width: 100%;
}
.chart-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 84px);
}
.choose {
  margin-top: 0.3rem;
  margin-left: 1.5rem;
  font-size: 1.5rem;
  height: 1rem;
}
</style>

